@using Variant = MudBlazor.Variant
@inherits StudioComponentBase
@using Elsa.Studio.Workflows.Services
@inject ILocalizer Localizer

<div>
    <MudText Typo="Typo.overline">@Localizer["Inputs"]</MudText>
    <MudStack>

        <MudButton
            StartIcon="@Icons.Material.Outlined.Add"
            Variant="Variant.Filled"
            Color="Color.Primary"
            Class="align-self-end"
            OnClick="OnAddInputClicked"
            Disabled="IsReadonly">
            @Localizer["Add input"]
        </MudButton>

        @if (!Inputs.Any())
        {
            <MudAlert Severity="Severity.Normal" Variant="Variant.Text" Icon="@Icons.Material.Outlined.Info">@Localizer["There are currently no inputs defined."]</MudAlert>
        }
        else
        {
            <MudSimpleTable Dense="true" Bordered="false" Striped="false" Elevation="0" Outlined="true" FixedHeader="true">
                <thead>
                <tr>
                    <th>@Localizer["Name"]</th>
                    <th>@Localizer["Type"]</th>
                    <th>@Localizer["Storage"]</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>

                @foreach (var input in Inputs)
                {
                    var storageDescriptor = input.StorageDriverType != null ? GetStorageDriverDescriptor(input.StorageDriverType) : default;
                    var storageDriverName = storageDescriptor != null ? storageDescriptor.DisplayName : @Localizer["None"];
                    var typeDescriptor = input.Type != null ? _variableTypes.FirstOrDefault(x => x.TypeName == input.Type) : default;
                    var typeName = typeDescriptor?.DisplayName ?? input.Type;
                    if(input.IsArray) typeName += "[]";
                    <tr>
                        <td>@input.Name</td>
                        <td>@typeName</td>
                        <td>@storageDriverName</td>
                        <td style="text-align: right;">
                            <MudMenu Icon="@Icons.Material.Filled.MoreVert" Disabled="IsReadonly">
                                <MudMenuItem Icon="@Icons.Material.Outlined.Edit" OnClick="@(() => OnEditClicked(input))">@Localizer["Edit"]</MudMenuItem>
                                <MudMenuItem Icon="@Icons.Material.Outlined.Delete" OnClick="@(() => OnDeleteClicked(input))">@Localizer["Delete"]</MudMenuItem>
                            </MudMenu>
                        </td>
                    </tr>
                }
                </tbody>
            </MudSimpleTable>
        }
    </MudStack>
</div>